<?php

namespace App\Logic\Auth\Form;

use App\Core\BaseListForm;
use App\Model\Auth\MenuModel;
use App\Util\CommonHelper;
use App\Util\UserIdentityHelper;

class MenuListForm extends BaseListForm{

    public function lists(){
        
        $where = [];
        
        $model = MenuModel::makeQueryModel($where);

        $model->field(['id','pid','title','identification','type','sort','state','icon','web_path','menu_type']);

        $model->with(['parent']);

        $model->order('sort','desc');
    
        $modelResult = $model->all();
        
        $list = [];
        foreach ($modelResult as $v) {
            $item                        = $v->toArray();
            $item['parent_name']         = $v->parent->title ?? '';
            $item['identification_list'] = explode(',', $v->identification);
            $list[]                      = $item;
        }

        $list = CommonHelper::listToTree($list,'id','pid','child');

        return $this->success($list);

    }
    
}